﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TalkServer
{
    public class TASKManager:List<TASK>
    {
        public TASKManager()
        #region >><<
        {

        }

        public bool isDispose { get; protected set; }
        public void Dispose()
        {
            isDispose = true;
            this.Clear();
        }
        #endregion

        public void Add(TCPGolbalInfo.RecordArgs args1,MSGGolbalInfo.ARGS args2,TaskDest dest)
        {
            TASK item = new TASK();
            item.ID = args2.ARGSID;
            item.Dest = dest;
            this.Add(item);
            if (this.Count > 1000)
            {
                this.RemoveAll(r => DateTime.Now.Subtract(r.StartTime).TotalMinutes > 10); 
            }
        }

        public bool FeedBack(MSGGolbalInfo.ARGS args)
        {
            TASK item = this.Find(r => r.ID == args.ARGSID);

            if (item != null )
            {
                if(item.Dest != null)
                    item.Dest(args);
                this.Remove(item);
            }
            
            return item != null;
        }
    }
}
